package com.bgrc.hubu12305.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bgrc.hubu12305.common.utils.UUIDUtils;
import com.bgrc.hubu12305.dao.OrderDao;
import com.bgrc.hubu12305.entity.OrderEntity;
import com.bgrc.hubu12305.entity.UserEntity;
import com.bgrc.hubu12305.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 包名:com.bgrc.hubu12305.service.impl
 * 用户:86182
 * 时间:20211214:252021/12/17
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {
    @Override
    public boolean isCheck(UserEntity userEntity,
                           String carriages,
                           String seatNo,
                           String startStation,
                           String endStation,
                           String trainNumber,
                           Integer price) {

        String orderId = UUIDUtils.getUUID();
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setId(orderId);
        //用户信息
        orderEntity.setUserName(userEntity.getUserName());
        orderEntity.setUserIdNumber(userEntity.getIdentityCard());
        orderEntity.setUserPhoneNum(userEntity.getTel());

        orderEntity.setTrainNumber(trainNumber);
        orderEntity.setStartStationName(startStation);
        orderEntity.setEndStationName(endStation);

        orderEntity.setCarriageNo(carriages);
        orderEntity.setSeatNo(seatNo);
        orderEntity.setOrderMoney(price);
        orderEntity.setOrderCreateTime(null);
        orderEntity.setOrderStatus("已支付");

        return this.save(orderEntity);
    }

    @Override
    public List<OrderEntity> queryPage(Integer currentPage, String userName) {
        QueryWrapper<OrderEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name",userName);

        System.out.println("service:"+userName);
        Page<OrderEntity> page = new Page<>(currentPage,5L);
        List<OrderEntity> records = baseMapper.selectPage(page, queryWrapper).getRecords();
        //page.getTotal();
        return records;
    }
    /**
     * 处理订单
    * */
}
